package com.fast.cron.db;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * db executor sql factory
 *
 * @author :leo.jie
 * @version :v1.0
 * @date :2018/9/29 14:10
 */
public interface DbHelperFactory {
    /**
     * query list
     *
     * @param sql  the sql will execute
     * @param para params list
     * @return result list
     * @throws SQLException the exception of executing sql
     */
    List<Map<String, Object>> query(String sql, Object... para) throws SQLException;

    /**
     * query list
     *
     * @param cls  cls class name of entry's mapper
     * @param sql  the sql will execute
     * @param para params list
     * @return result list
     * @throws SQLException the exception of executing sql
     */
    <T> List<T> query(Class<T> cls, String sql, Object... para) throws SQLException;

    /**
     * query one
     *
     * @param cls  class name of entry's mapper
     * @param sql  the sql will execute
     * @param para params list
     * @return one entry
     * @throws SQLException the exception of executing sql
     */
    <T> T queryOne(Class<T> cls, String sql, Object... para) throws SQLException;

    /**
     * query count
     *
     * @param sql  the sql will execute
     * @param para params list
     * @return the count of result
     * @throws SQLException the exception of executing sql
     */
    Long queryCount(String sql, Object... para) throws SQLException;

    /**
     * update
     *
     * @param sql  the sql will execute
     * @param para params list
     * @return rows number
     * @throws SQLException the exception of executing sql
     */
    int update(String sql, Object... para) throws SQLException;


    /**
     * insert
     *
     * @param sql  the sql will execute
     * @param para params list
     * @return rows number
     * @throws SQLException the exception of executing sql
     */
    Long insert(String sql, Object... para) throws SQLException;

    /**
     * bach execute sql
     *
     * @param sql    the sql will execute
     * @param params para params list
     * @throws SQLException the exception of executing sql
     */
    void executeBach(String sql, Object[][] params) throws SQLException;

    /**
     * start transaction
     *
     * @throws SQLException the exception of executing sql
     */
    void startTransaction() throws SQLException;

    /**
     * commit transaction
     *
     * @throws SQLException the exception of executing sql
     */
    void commit() throws SQLException;

    /**
     * rollback transaction
     *
     * @throws SQLException the exception of executing sql
     */
    void rollback() throws SQLException;
}
